<template>
  <div class="app-container customer-div">
    <div style="margin-top: 20px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="130px">
        <el-form-item label="发货单号：">
          <el-input v-model="listQuery.deliverSn" clearable></el-input>
        </el-form-item>
        <el-form-item label="客户编号：">
          <el-input v-model="listQuery.customerNumber" clearable></el-input>
        </el-form-item>
        <el-form-item label="客户名称：">
          <el-select
            clearable
            v-model="listQuery.customerName"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod"
            :loading="loading">
            <el-option
              v-for="item in customerList"
              :key="item.customerName"
              :label="item.customerName"
              :value="item.customerName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单编号：">
          <el-input v-model="listQuery.orderSn" clearable></el-input>
        </el-form-item>
        <el-form-item label="牌号：">
          <el-select v-model="listQuery.kingGoodsId" filterable placeholder="请选择" clearable>
            <el-option
              v-for="item in goodsList"
              :key="item.kingId"
              :label="item.goodsSn"
              :value="item.kingId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="销售员：">
          <el-select v-model="listQuery.userId" placeholder="请选择" clearable filterable>
            <el-option
              v-for="item in userOptionList"
              :key="item.userId"
              :label="item.realName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="缓急程度：">
          <el-select v-model="listQuery.urgencyDegree" class="input-width" style="width:250px" placeholder="请选择" clearable multiple>
            <el-option value="暂缓" label="暂缓" :key="0"></el-option>
            <el-option value="下月" label="下月" :key="1"></el-option>
            <el-option value="等通知" label="等通知" :key="2"></el-option>
            <el-option value="未标记" label="未标记" :key="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发货日期：">
          <el-date-picker
            v-model="listQuery.shipTime"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="loading"
        :data="list"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          prop="deliverSn"
          label="发货单号"
          align="center"
          min-width="150">
        </el-table-column>
        <el-table-column
          label="客户"
          align="center"
          min-width="180">
          <template slot-scope="scope">
            <div>
              {{scope.row.customerNumber}}
            </div>
            <!--是否有权限-->
            <div v-if="scope.row.isShowCustomerName">{{scope.row.customerName}}</div>
          </template>
        </el-table-column>

        <el-table-column
          label="订单号"
          align="center"
          min-width="180">
          <template slot-scope="scope">
            {{scope.row.orderSn}}
          </template>
        </el-table-column>
        <el-table-column
          label="商品牌号"
          align="center"
          min-width="180">
          <template slot-scope="scope">
            {{scope.row.goodsSn}}
          </template>
        </el-table-column>
        <el-table-column
          prop="shipTime"
          label="发货日期"
          align="center"
          min-width="150">
        </el-table-column>
        <el-table-column
          prop="shipNum"
          label="发货数量"
          align="center"
          min-width="100">
        </el-table-column>
        <el-table-column
          label="业务员"
          align="center"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.userName}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="缓急程度"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.urgencyDegree}}
          </template>
        </el-table-column>


      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>




  </div>
</template>

<script>
import { orderGoodsList,getCustomerOption,getUserOption,getOrderStatList} from '@/api/partner'
import {getInvoiceUrgencyList,setInvoiceUrgency} from '@/api/order'
import {formatDate} from '@/utils/date';
import store from '@/store'
import { mapGetters } from 'vuex'
const defaultListQuery={
  "tab": "all", //my-我的，department-部门，all-全部
  "userId": "", //业务员ID
  "deliverSn": "", //发货单号
  "customerName": "", //客户名称
  "customerNumber": "", //客户编码
  "orderSn": "", //订单号
  "kingGoodsId": "", //商品牌号
  "urgencyDegree": ["暂缓", "下月", "等通知"], //缓急程度，暂缓，下月，等通知
  "shipTime": [], //发货日期
  "pageNum": 1,
  "pageSize": 10
};

export default {
  name: "financeDeliverInvoiceUrgency",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      list:[],
      count:0,
      loading:false,
      goodsList:[],
      customerList:[],
      userOptionList:[],
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),



  },
  created() {
    this.getListData();
    this.getUserOptionList()
    this.getgoodsList()
  },
  filters: {
    formatTime(time) {
      let date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd')
    },
  },
  methods:{


    getgoodsList(){
      orderGoodsList().then((res)=>{
        this.goodsList = res.list
      })
    },


    //获取订单状态列表
    getOrderStatListData(){
      getOrderStatList().then((res)=>{
        this.orderStateList = res;
      })
    },



    //获取员工下拉选项
    getUserOptionList(){
      getUserOption().then((res)=>{
        this.userOptionList = res;
      })
    },
    //查询获取客户列表
    remoteMethod(query) {
      if(query && query!= ''){
        this.loading = true;
        getCustomerOption({keywords:query}).then(response => {
          this.customerList = response;
          this.loading = false;
        }).catch(()=>{
          this.loading = false;
        });
      }
    },
    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getListData();
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getListData();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getListData();
    },

    getListData(){
      this.loading = true;
      getInvoiceUrgencyList(this.listQuery).then((res)=>{
        this.list = res.list;
        this.count = res.count;
        this.loading = false;
      }).catch(()=>{
        this.loading = false;
      })
    },

  },
}
</script>

<style scoped lang="scss">

</style>
